﻿
@{
    Layout = null;
}

<table id="category" class="easyui-datagrid" style="width:100%;height:100%"
       url="/Admin/SelectCategoryList"
       title="分类管理" iconcls="icon-save" fitcolumns="true" sortname="CreateTime" sortorder="desc"
       pagination="true"
       idfield="CategoryId"
       fit="true"
       noheader="true"
       striped="true"
       singleselect="true"
       checkonselect="false"
       nowrap="true"
       loadmsg='正在加载……'
       rownumbers="true"
       frozencolumns="[[{ field:'ck'  checkbox:false }]]"
       toolbar="#tbCategory">
    <thead>
        <tr>
            <th field="CategoryId" width="10" align="center">标识</th>
            <th field="CategoryName" width="100" align="center">分类名称</th>
            <th field="BelongUnit" width="100" align="center">所属菜单</th>
            <th field="CreateTime" width="100" align="center" formatter="formatTime">创建时间</th>
        </tr>
    </thead>
</table>
<div id="tbCategory">
    <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="javascript:AddCategory()">添加</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-cut" plain="true" onclick="javascript:UpdateCategory()">修改</a>
    @*<a href="#" class="easyui-linkbutton" iconcls="icon-cancel" plain="true" onclick="javascript:Delete()">删除</a>*@
</div>

<div id="AddCategory" class="easyui-dialog" title="添加分类" style="width:400px;height:300px;padding:10px" buttons="#category-dlg-buttons" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
    <div class="easyui-panel" data-options="fit:true,border:false">
        <form id="addForm" method="post" action="/admin/AddCategory">
            <input type="hidden" name="CategoryId" id="category_CategoryId" />
            <div style="margin-bottom:15px">
                <input class="easyui-textbox" name="CategoryName" id="CategoryName" label="名称:" labelPosition="top" style="width:80%;">
            </div>
            <div style="margin-bottom:15px">
                <label>所属分类:</label><br /><br />
                <select name="BelongUnit" id="BelongUnit" class="easyui-combobox" style="width:50%" data-options="multiple:false,editable: false">
                    <option value="留学教育" selected="selected">留学教育</option>
                    <option value="移民签证">移民签证</option>
                    <option value="教育培训">教育培训</option>
                    <option value="最新资讯">最新资讯</option>
                    <option value="关于我们">关于我们</option>
                </select>
            </div>
        </form>
    </div>
</div>
<div id="category-dlg-buttons">
    <table cellpadding="0" cellspacing="0" style="width:100%">
        <tr>
            <td>
                @*<img src="email.gif" />*@
            </td>
            <td style="text-align:right">
                <a href="#" class="easyui-linkbutton" iconcls="icon-save" onclick="javascript:SaveCategory()">保存</a>
                <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript: $('#AddCategory').dialog('close')">取消</a>
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">


    function AddCategory() {
        category_clear();
        $("#AddCategory").dialog({ title: "添加分类" });
        $("#AddCategory").dialog('open');
    }
    function SaveCategory() {
        $("#addForm").form('submit', {
            success: function (data) {
                data = eval("(" + data + ")");
                if (data.result) {
                    $("#AddCategory").dialog('close');
                    if ($("#category_CategoryId").val() > 0)//ID存在
                    {
                        topCenter("修改分类", "修改成功!");
                    }
                    else {
                        topCenter("添加分类", "添加成功!");
                    }
                    $("#category").datagrid('reload');
                }
                else {
                    if ($("#category_CategoryId").val() > 0)//ID存在
                    {
                        topCenter("修改分类", "修改失败!");
                    }
                    else {
                        topCenter("添加分类", "添加失败!");
                    }
                }

            }
        })
    }

    function UpdateCategory() {
        category_clear();
        var row = $("#category").datagrid("getSelected");
        if (row == null) {
            topCenter("提示", "请选择要修改的数据!");
            return;
        }
        $("#category_CategoryId").val(row.CategoryId);
        $("#CategoryName").textbox('setValue', row.CategoryName);
        $("#BelongUnit").combobox("setValue", row.BelongUnit);
        $("#AddCategory").dialog({ title: "修改分类" });
        $("#AddCategory").dialog('open');
    }

    function DeleteCategory() {
        var row = $("#category").datagrid("getSelected");
        if (row == null) {
            topCenter("提示", "请选择要删除的数据!");
            return;
        }
        $.post('/Admin/DeleteCategory', { categoryId: row.CategoryId }, function (data) {
            if (data.result) {
                topCenter("提示", "删除成功!");
                $("#category").datagrid('reload');
            } else {
                topCenter("提示", "删除失败!");
            }
        });
    }

    function category_clear() {
        $("#category_CategoryId").val("");
        $("#CategoryName").textbox("setValue", "");
    }
</script>
